package com.metrics.ctrls.imp;

import static com.metrics.objects.Options.*;

import com.database.objects.*;
import com.metrics.ctrls.IModelCtrl;
import com.metrics.extractors.*;
import com.metrics.objects.Metric;

public class ModelCtrl implements IModelCtrl {

	private MetricExtractorMap metricExtractorMap;

	@Override
	public Double calculateModel(Developer developer, Metric[] metrics, Status[] statuss, Type[] types, Double[] constants) {
		Double total = 0.0;
		for (int i = 0; i < types.length; i++) {
			Double constant = constants[i] / 100;
			Metric metric = metrics[i];
			Status status = statuss[i];
			Type type = types[i];

			MetricExtractor extractor = metricExtractorMap.get(metric);
			Double contributionDeveloper = extractor.extract(developer, type, status, START_DATE_DEFAULT, FINISH_DATE_DEFAULT);
			Double contributionTotal = extractor.extractTotal(developer.getProject(), type, status, START_DATE_DEFAULT, FINISH_DATE_DEFAULT);

			total += contributionTotal > 0 ? (constant * (contributionDeveloper / contributionTotal)) : 0;
		}

		return total;
	}

	public void setMetricExtractorMap(MetricExtractorMap metricExtractorMap) {
		this.metricExtractorMap = metricExtractorMap;
	}

}